#include "Bind_Result.h"


Bind_Result::Bind_Result(char *raspuns,bool succes,char* user,char *pass):LDAP_Result(raspuns,succes)
{

	this->User_name = new char[strlen(user)+1];
	strcpy(this->User_name,user);

	this->Password = new char[strlen(pass)+1];
	strcpy(this->Password,pass);

}


Bind_Result::~Bind_Result(void)
{
}

void Bind_Result::afisareResult()
{
	if(Succes==false)
		throw new Bind_Result_Exception("Operatia de bind nu a reusit !!",1);

	if(!strcmp(raspuns,"The server send a NULL message!"))
	{
		printf("\n->The Client didn't found in the LDAP Server entry directory!");
		Succes = false;
		AuthState = false;
		return;
	}

	Atribut<char *>a1;
	
	char sep[]={":\n"},*p=NULL;
	char *sir = new char[strlen(raspuns)+1];
	strcpy(sir,raspuns);
	
	p=strtok(raspuns,sep);
	while(p)
	{
		a1.setNume(p);
		p=strtok(NULL,sep);
		a1.setValue(p);
		p=strtok(NULL,sep);

		atribute.push_back(a1);
	}

	
	printf("\n->The Distinguished Names of the client is:\n'dn: %s",atribute[0].daAtribut());



	if(!strcmp(User_name,atribute[3].daAtribut()+1) && !strcmp(Password,atribute[2].daAtribut()+1))
	{
		printf("\n\n->Succes:The client is login at the LDAP Server...\n");
		Succes = true;
		AuthState = true;
	}
	else
		if(!strcmp(User_name,atribute[3].daAtribut()+1) && !strcmp(Password,atribute[4].daAtribut()+1))
		{
			printf("\n\n->Succes:The LDAP Administrator is login at the LDAP Server...\n");
			Succes = true;
			AuthState = true;
		}
	else
	{
		printf("\n->The user_name or the password didn't match...Please try again...");
		Succes = false;
		AuthState = false;
	}

}
